package com.zjj.edu.system.service.impl;

import com.zjj.edu.common.constant.UserConstants;
import com.zjj.edu.common.utils.DateUtils;
import com.zjj.edu.common.utils.StringUtils;
import com.zjj.edu.system.domain.SysCampus;
import com.zjj.edu.system.mapper.SysCampusMapper;
import com.zjj.edu.system.service.ISysCampusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 校区Service业务层处理
 *
 * @author zjj
 * @date 2020-06-02
 */
@Service
public class SysCampusServiceImpl implements ISysCampusService
{
    @Autowired
    private SysCampusMapper sysCampusMapper;

    /**
     * 查询校区
     *
     * @param id 校区ID
     * @return 校区
     */
    @Override
    public SysCampus selectSysCampusById(Long id)
    {
        return sysCampusMapper.selectSysCampusById(id);
    }

    /**
     * 查询校区列表
     *
     * @param sysCampus 校区
     * @return 校区
     */
    @Override
    public List<SysCampus> selectSysCampusList(SysCampus sysCampus)
    {
        return sysCampusMapper.selectSysCampusList(sysCampus);
    }

    /**
     * 新增校区
     *
     * @param sysCampus 校区
     * @return 结果
     */
    @Override
    public int insertSysCampus(SysCampus sysCampus)
    {
        sysCampus.setCreateTime(DateUtils.getNowDate());
        return sysCampusMapper.insertSysCampus(sysCampus);
    }

    /**
     * 修改校区
     *
     * @param sysCampus 校区
     * @return 结果
     */
    @Override
    public int updateSysCampus(SysCampus sysCampus)
    {
        sysCampus.setUpdateTime(DateUtils.getNowDate());
        return sysCampusMapper.updateSysCampus(sysCampus);
    }

    /**
     * 删除校区对象
     *
     * @return 结果
     */
    @Override
    public int deleteSysCampusByIds(SysCampus sysCampus)
    {
        return sysCampusMapper.deleteSysCampusByIds(sysCampus);
    }

    @Override
    public String checkNameUnique(SysCampus vo) {
        Long id = StringUtils.isNull(vo.getId()) ? -1L : vo.getId();
        SysCampus info = sysCampusMapper.checkNameUnique(vo.getName(), vo.getTenantId());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue())
        {
            return UserConstants.NAME_NOT_UNIQUE;
        }
        return UserConstants.NAME_UNIQUE;
    }

    @Override
    public int selectCampusNum(long tenantId) {
        return sysCampusMapper.selectCampusNum(tenantId);
    }

    @Override
    public List<SysCampus> selectCampusAll(long tenantId) {
        return sysCampusMapper.selectCampusAll(tenantId);
    }
}
